<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<jsp:useBean id="connDbBean" scope="page" class="dataconn.dataconn"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<%
int page_persize=2;//每页显示记录数
int page_total=0;//总的页数
int page_now=1;//当前页码
int rs_total=0;//总的记录数
String sql="select * from userlist"; 
ResultSet rs=connDbBean.executeQuery(sql); 
rs.last();//指针到最后一条记录
rs_total=rs.getRow();//读出当前行号即总的记录数
if (rs_total % page_persize==0)
    page_total=rs_total/page_persize;
else
    page_total=rs_total/page_persize+1;
try{
if (!(request.getParameter("page_now")==null || request.getParameter("page_now").equals("")))
page_now=Math.min(Math.abs(Integer.parseInt(request.getParameter("page_now"))),page_total);
}catch(java.lang.NumberFormatException e){
out.print("指定页码格式不正确"+e);
}
if (page_now==0) page_now=1;
rs.absolute((page_now-1)*page_persize+1);
for(int i=1;i<=page_persize;i++)
    {
 //循环体
    if (!rs.next()) break;//如果记录数不够则中断循环
    }
rs.close();
connDbBean.closeStmt();   
connDbBean.closeConn();   

//显示页码导航，其中的问号表示由当前页面处理。
out.print("总共"+rs_total+"条记录　");
if (page_total>1){
out.print("当前第"+page_now+"页　");
out.print("共"+page_total+"页　");
if(page_now!=1) {
        out.print("<a href=?page_now=1>首页</a>　");
        out.print("<a href=?page_now="+(page_now-1)+">上一页</a>　");
    }
if(page_now!=page_total){
    out.print("<a href=?page_now="+(page_now+1)+">下一页</a>　");
    out.print("<a href=?page_now="+page_total+">尾页</a>　");
    }
%>
<form action="?" method="post"><!--问号表示由当前页面处理 -->
    <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
      <tr>
        <td><div align="center">跳转到：
          <input name="page_now" type="text" size="3" />
                <input name="submit" type="submit" value="提交" />
        </div></td>
      </tr>
    </table>
</form>
<% } %>
</body>
</html>